/// @tags: Search List
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

namespace BlueQuantum {

int const N = 1e5 + 5, M = 1e3;

struct Node {
  Node *u, *d, *l, *r, *c;
  int s;
} h[N], d[N], *cl[N];

struct LNode : Node {};

int ans, l[M], maxn[N];
char str[N];

inline void insert(Node* const cur) { cur->l->r = cur->r->l = cur; }
inline void insert(LNode* const cur) { cur->u->d = cur->d->u = cur, cur->c->s++; }

inline void del(Node* const cur) { cur->r->l = cur->l, cur->l->r = cur->r; }
inline void del(LNode* const cur) { cur->u->d = cur->d, cur->d->u = cur->u, cur->c->s--; }

void dfs() {
  Node* p = h;
  for (Node* i = h->r; i != h; i = i->r)
    if (i->s < p->s) p = i;
  if (p->s == 0) return;
  for (Node* k = p->d; k != p; k = k->d)
    for (Node* l = k->r; l != k; l = l->r) del(static_cast<LNode*>(l));
  del(p);
  for (Node* i = p->d; i != p; i = i->d) {
    for (Node* j = i->r; j != i; j = j->r) {
      for (Node* k = j->c->d; k != j->c; k = k->d)
        for (Node* l = k->r; l != k; l = l->r) del(static_cast<LNode*>(l));
      del(j->c);
    }
    if (h->r == h) ++ans;
    else
      dfs();
    for (Node* j = i->l; j != i; j = j->l) {
      insert(j->c);
      for (Node* k = j->c->u; k != j->c; k = k->u)
        for (Node* l = k->l; l != k; l = l->l) insert(static_cast<LNode*>(l));
    }
  }
  insert(p);
  for (Node* k = p->u; k != p; k = k->u)
    for (Node* l = k->l; l != k; l = l->l) insert(static_cast<LNode*>(l));
}

inline int calc(int l, int r) {
  int x = 0;
  for (int i = l; i <= r; ++i) x = x * 10 + str[i] - '0';
  return x;
}

inline int main() {
  int len, n = 0;
  cin >> (str + 1);
  len = strlen(str + 1);
  for (int i = 1; i < M; ++i) l[i] = l[i / 10] + 1;
  for (int i = 1; i < M; ++i) {
    if ((l[i] += l[i - 1]) == len) {
      n = i;
      break;
    }
  }
  if (!n) return cout << '0', 0;
  Node *dptr = d, *last, *rh;
  for (int i = 1; i <= len + n; ++i)
    cl[i] = &h[i], h[i].l = &h[i - 1], h[i - 1].r = &h[i];
  h->l = &h[len + n], h[len + n].r = h;
  h->s = M;
  for (int i = 1, tmp; i <= len; ++i)
    for (int j = 0; j <= 2 && i + j <= len; ++j)
      if ((tmp = calc(i, i + j)) <= n) {
        last = rh = dptr;
        for (int k = 0; k <= j; ++k)
          dptr->l = last, last->r = dptr, cl[i + k]->d = dptr, dptr->u = cl[i + k],
          dptr->c = &h[i + k], last = dptr, cl[i + k] = dptr, dptr->c->s++, ++dptr;
        dptr->l = last, last->r = dptr, cl[len + tmp]->d = dptr, dptr->u = cl[len + tmp],
        dptr->c = &h[len + tmp], last = dptr, cl[len + tmp] = dptr, dptr->c->s++, ++dptr;
        last->r = rh, rh->l = last;
      }
  for (int i = 1; i <= len + n; ++i) cl[i]->d = &h[i], h[i].u = cl[i];
  dfs();
  cout << ans;
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("Mysterious Permutation.in", "r", stdin);
  freopen("Mysterious Permutation.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
